import yaml
import os
import jupytext




yaml.warnings({'YAMLLoadWarning':False}) 
f=open('config.yml','r',encoding='utf-8')

cfg=f.read()
lists=yaml.load(cfg)

folder='src'
nb_list=lists[folder]

context=''
info= folder+'\n'
for item in nb_list:
    info=info+'   |--- '+item+'\n'
    with open(folder+'/'+item, 'r', encoding='utf-8') as f:
        context= context+'# %%\n'+f.read()+'\n'

nb=jupytext.reads(context,fmt='py')
jupytext.write(nb, 'main.ipynb', fmt='jl:percent')
print("Successfully sync\n %s -> main.ipynb" % info)
